package prod_cons;

import Pool.EliminationPool_V1;
import Tools.ConfigurationManager;

public class EDContainer implements TaskContainer {
	
	EliminationPool_V1<Runnable> edPool;
	
	public EDContainer() {
		String configurationFile = System.getProperty("config");
		if (configurationFile == null) {
			configurationFile = "config.xml";
		}
		ConfigurationManager.setConfigurationPath(configurationFile);
		int poolCapacity = ConfigurationManager.getConfigurationValue("poolCapacity", 2);
		int treeCapacity = ConfigurationManager.getConfigurationValue("treeCapacity", 8);
		int treeLevels = ConfigurationManager.getConfigurationValue("treeLevels", 2);
		edPool = new EliminationPool_V1<Runnable>(poolCapacity, treeCapacity, treeLevels);
	}
	
	@Override
	public void put(Runnable task) {
		try {
			edPool.put(task);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}		
	}

	@Override
	public Runnable get() {
		try {
			return edPool.get();
		} catch (InterruptedException e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public void setConsumersNum(int consumersNum) {
	}

	@Override
	public void registerConsumer() {
	}

}
